Skip to content

fix(ffi): pad underfull single-query search results - #135

Open
miomiocat wants to merge 1 commit into
apache:mainfrom
miomiocat:codex/pvi-ffi-pad-single-query-results
Open

miomiocat wants to merge 1 commit into
apache:mainfrom
miomiocat:codex/pvi-ffi-pad-single-query-results

Conversation

@miomiocat

Copy link
Copy Markdown

Closes #134.

A single query can return fewer matches than requested. Preserve those matches in the caller’s fixed-size output buffers and fill the unused tail with the existing ID and distance sentinels. Only the unused slots are padded.

All single-query entry points, including filtered searches, use this behavior. Batch calls still require a complete result matrix. The C signatures and on-disk format are unchanged.

Validation

Added cases for two returned hits with four requested slots, and for a short batch result.

Local checks passed with cargo fmt --all -- --check and cargo build --locked -p paimon-vindex-ffi --lib. Tests are left to upstream CI.

Fill unused single-query result slots with the missing ID and distance sentinels. Keep batch output lengths strict and validate the native ID and distance counts before writing the output buffers.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-6
AI-Contributed/Feature: 68/68
AI-Contributed/UT: 0/0
@JingsongLi

Copy link
Copy Markdown
Contributor

PR #124 already covers padding for underfull single-query results. The C regression test added there requests three results, matches two rows, and checks that the last slot contains -1 and FLT_MAX.

Could you share a minimal test case that reproduces the issue through the public C API on the current main branch?

@miomiocat

miomiocat commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

I traced the public single-query entry points again. The IVF wrapper pads to K, and DiskANN also pads its underfull results before the FFI copy. The C test in #124 already checks the two-hits-for-three case, including both sentinels. My added test only invokes the private copy helper with a short slice. I don't have a public C API reproducer on main or evidence that a second padding layer is needed here. Thanks for pointing me to the existing coverage.

The downstream result adapter skips row ID -1 before converting scores. I also compiled its shared-searcher FFI path with the strict copy helper from main. The deployed downstream build available to me predates #124, so an end-to-end run of the upgrade is still outstanding. I will keep this open until that check is complete.

@miomiocat

Copy link
Copy Markdown
Author

StarRocks verification is still in progress. The shared-searcher build passed with the strict result-length check from main. The remaining check is an end-to-end query that requests more neighbors than match, using #124 without the patch in this PR. If StarRocks returns the matching rows and scores correctly, I’ll close this PR and #134.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-query FFI searches reject underfull native results

2 participants